﻿using System;

namespace GLDotNet
{
    public abstract class GLObject : DisposableObject
    {
        protected GraphicsDevice GraphicsDevice
        {
            get;
            private set;
        }

        protected GLContext Context
        {
            get { return this.GraphicsDevice.Context; }
        }

        public uint Handle
        {
            get;
            protected set;
        }

        protected GLObject(GraphicsDevice graphicsDevice)
        {
            if (graphicsDevice == null)
                throw new ArgumentNullException("graphicsDevice");

            this.GraphicsDevice = graphicsDevice;
        }

        protected override void DisposeManagedResources()
        {
        }

        protected override void DisposeUnmanagedResources()
        {
            if (!this.GraphicsDevice.IsContextDisposed)
                this.DeleteObject();
        }

        protected abstract void DeleteObject();
    }
}
